package com.loop.mapDemo;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Practice {
    public static void main(String[] args) {
        /*Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个字符串:");
        String input = scanner.next();*/
        String s = "abcdsscchdyti12";
        countChar(s);
    }

    public static void countChar(String str){
        char[] ch = str.toCharArray();
        HashMap<Character, Integer> map = new HashMap<>();
        for (char c:  ch) {
            boolean b = map.containsKey(c);
            if (b){
                Integer integer = map.get(c);
                map.put(c,++integer);
            }else {
                map.put(c,1);
            }
        }
        Set<Map.Entry<Character, Integer>> entries = map.entrySet();
        for (Map.Entry<Character, Integer> entry: entries) {
            System.out.println(entry.getKey()+"有"+entry.getValue()+"个");
        }
    }
}
